package com.zzyl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//@SpringBootTest
public class text {

    @Test
    public void HttpGetTest1() {
        String s = HttpUtil.get("https://www.baidu.com");
        System.out.println(s);
    }

    @Test
    public void HttpGetTest2() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("pageNum", "1");
        map.put("pageSize", "5");
        String s = HttpUtil.get("http://localhost:9995/nursing/plan/search", map);
        System.out.println(s);
    }

    @Test
    public void HttpGetTest3() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("pageNum", "1");
        map.put("pageSize", "1");
        HttpResponse execute = HttpUtil.createRequest(Method.GET, "http://localhost:9995/nursing/plan/search").form(map).execute();
        if (execute.getStatus() == 200) {
            System.out.println(execute.body());
        }
    }

    @Test
    public void HttpPostTest1() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("image", "1.jpg");
        map.put("name", "测试哈哈哈256");
        map.put("nursingRequirement", "测试看看能不能添加护理项目");
        map.put("orderNo", 5);
        map.put("price", 2);
        map.put("unit", "次");
        String jsonStr = JSONUtil.toJsonStr(map);
        String s = HttpUtil.post("http://localhost:9995/nursing_project", jsonStr);
        System.out.println(s);
    }

    @Test
    public void HttpPostTest2() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("image", "1.jpg");
        map.put("name", "测试哈哈哈257");
        map.put("nursingRequirement", "测试看看能不能添加护理项目");
        map.put("orderNo", 5);
        map.put("price", 2);
        map.put("unit", "次");
        HttpResponse execute = HttpUtil.createRequest(Method.POST, "http://localhost:9995/nursing_project").body(JSONUtil.toJsonStr(map)).execute();

        if (execute.getStatus() == 200) {
            System.out.println(execute.body());
        }
    }

    @Test
    public void tqTest() {
        String host = "https://ali-weather.showapi.com";
        String path = "/hour24";
        String method = "GET";
        String appcode = "52b9ad5600e048edb7be8d0eb808629a";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, Object> querys = new HashMap<String, Object>();
        querys.put("area", "济南");
        querys.put("areaCode", "areaCode");


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            //HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);

            HttpResponse execute = HttpUtil.createRequest(Method.GET, host + path).addHeaders(headers).form(querys).execute();
            System.out.println(execute);
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
